Example Z80 assembly programs (was:ASM source code)

Started by arnoldemu, 10:59, 04 April 10

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ynot.zer0

Quote from: arnoldemu on 23:52, 28 April 10
New source:

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

Shows:
1. How to use KM_TEST_KEY to read keyboard (uses key numbers)
2. How to draw a tilemap to the screen (20 tiles wide and 12 tall). The tilemap is for a static screen (no scroll).
3. How to join tilemaps together to make a larger map (you can press up/down/left/right cursors to move to other screens).

Quick tile gfx by Markus. Thanks :)


That sample is absolutely SUPERB! It is just what I was after knowing.  Thank you so much for posting these samples they are a tremendous help to us newbie coders  8)   keep 'em coming!


arnoldemu

Quote from: ynot.zer0 on 15:18, 29 April 10

That sample is absolutely SUPERB! It is just what I was after knowing.  Thank you so much for posting these samples they are a tremendous help to us newbie coders  8)   keep 'em coming!
np. I have a few more ideas (hardware scrolling a tilemap, software scrolling a tilemap, reducing/stopping flicker in sprites, double buffering) and then I will ask for suggestions.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

redbox

Quote from: arnoldemu on 13:36, 30 April 10
hardware scrolling a tilemap, software scrolling a tilemap, reducing/stopping flicker in sprites, double buffering

YES!

I have been slaving over a tilemap routine and it's been great to see how you've done it.

Would definitely like some pointers on quick double buffering (scrolling has been taken care of by the ASIC for me  ;) ).

Devilmarkus

I also wrote a small assembler routine today.
I use it to load several screens into ram banks.
This routine provides 2 RSX commands for BASIC:
|BANK,bank 
|COPY 

You can load a screen to bank &C4 and copy it to screen: 
10 MEMORY &3FFF 
20 |BANK,&C4:LOAD"MYSCREEN.BIN",&4000
30 |COPY
 
Here's the source:
        nolist
        org #8000

        LD      HL,BufferRsx
        LD      BC,PtrRsx
        JP      #BCD1

PtrRsx:
        DW      RSX_TABLE
        JP      Bank
        JP      Copy

RSX_TABLE:
        DB      "BAN","K"+#80
        DB      "COP","Y"+#80

Bank:
        LD      A,(IX+0)
        LD      B,#7F
        OUT     (C),A
        RET 

Copy:
        LD      HL,#4000
        LD      BC,#4000
        LD      DE,#c000
        LDIR
        RET
       
BufferRsx:
        DS      4
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

arnoldemu

Quote from: Devilmarkus on 23:58, 23 June 10
I also wrote a small assembler routine today.
I use it to load several screens into ram banks.
This routine provides 2 RSX commands for BASIC:
|BANK,bank 
|COPY 

You can load a screen to bank &C4 and copy it to screen: 
10 MEMORY &3FFF 
20 |BANK,&C4:LOAD"MYSCREEN.BIN",&4000
30 |COPY
 
Here's the source:
        nolist
        org #8000

        LD      HL,BufferRsx
        LD      BC,PtrRsx
        JP      #BCD1

PtrRsx:
        DW      RSX_TABLE
        JP      Bank
        JP      Copy

RSX_TABLE:
        DB      "BAN","K"+#80
        DB      "COP","Y"+#80

Bank:
        LD      A,(IX+0)
        LD      B,#7F
        OUT     (C),A
        RET 

Copy:
        LD      HL,#4000
        LD      BC,#4000
        LD      DE,#c000
        LDIR
        RET
       
BufferRsx:
        DS      4

A nice example of RSX commands.

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

Devilmarkus

The same code but modified with double buffering the screens:
        nolist
        org #8000

        LD      HL,BufferRsx
        LD      BC,PtrRsx
        JP      #BCD1

PtrRsx:
        DW      RSX_TABLE
        JP      Bank
        JP      Copy

RSX_TABLE:
        DB      "BAN","K"+#80
        DB      "COP","Y"+#80

Bank:
        LD      A,(IX+0)
        LD      B,#7F
        OUT     (C),A
        RET 

Copy:
       LD    BC,#BC0C
       OUT    (C),C

       LD    BC,#BD10
       OUT    (C),C        ; switch display to #4000 bank #C0

       LD     HL,#4000
       LD    DE,#C000
       LD    BC,#4000
       LDIR
       LD    BC,#BD30
       OUT    (C),C        ; switch display to #C000
       LD    BC,#7FC0
       OUT    (C),C        ; switch to bank #C0
       LD    HL,#C000
       LD    DE,#4000
       LD    BC,#4000
       LDIR
       RET
       
BufferRsx:
        DS      4
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

arnoldemu

New source:

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

This code uses the firmware to show:
1. How to sync with the firmware colour. So if you do ink 1,2,3 you can know for definite when this ink is colour 2 and when it is colour 3 and to ensure it always happens when you want it to.
2. How to set the colours using MC_SET_INK
3. How to define the screen base using SCR_SET_BASE and how to toggle screen between starting at &4000 and &c000.
4. How to change the mode using MC_SET_MODE so that the mode is changed without CLS.

This example is good if you want to make video modes which give the illusion of higher resolution or more colours by "flicking"/swapping the screens, colours and modes.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

arnoldemu

New source:

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

This code shows:
1. How to get the current drive number
2. How to initialise the disc rom after loading this file (BASIC will disable all roms, effectively going to
cassette mode)
3. How to set the current drive back again
4. Using a list of files, and loading each file one-by-one. When we get to the end of the list
going back to the first file again. Good for slideshows ;)

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

arnoldemu

Updated source:

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

Updated overscan code so that it supports crtc type 2 (changed register 3 value).
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Executioner

Quote from: arnoldemu on 23:30, 20 July 10
Updated overscan code so that it supports crtc type 2 (changed register 3 value).

Your link is wrong: try http://www.cpctech.org.uk/source/overscn.asm

arnoldemu

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

Axelay

Thought I'd have a go at some commented source of a variation of the sprite code from the 64k version of Star Sabre.  This example only uses one screen, runs with firmware and interrupts, and isn't well optimised.  The source has been tested under Winape.

This demonstrates using a look up table to generate an address list for all the sprites, then using that list when printing, then clearing the sprites.  The idea being that the more things the list is used for, the more useful it becomes to generate the addresses just the once as a separate process (for example, you might need to save & restore the background, or check for background collisions).  It also shows how the look up table can be used for easy 'sprite clipping' on the top and bottom edges of the screen.

Devilmarkus

Thanks for sharing.
To let JavaCPC compile this piece of code, I have a question:

.ScoreText
    text "Score:10000 Lives:3",0


when I replace it to:

.ScoreText
    db "Score:10000 Lives:3",0

it compiles.
So what's the difference between 'text' and 'db'?
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

Axelay

Quote from: Devilmarkus on 18:22, 23 July 10
So what's the difference between 'text' and 'db'?

Nothing at all, I guess 'text' must be specific to Maxam.

fano

"NOP" is the perfect program : short , fast and (known) bug free

Follow Easter Egg products on Facebook !

arnoldemu


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

New source:

- Shows how to play samples using digiblaster, amdrum and AY sound chip.
- All source sample data should be raw (e.g. no headers), 8-bit signed samples.
You can use Markus' tools to make this.
- shows how to create an RSX

Markus has been using similar code in his new productions.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Devilmarkus

Quote from: arnoldemu on 23:56, 17 September 10
Markus has been using similar code in his new productions.

Here's my tool I used to transform 8 bit mono WAV-files to RAW.


How to use?
- Simple: Just keep the default settings. No changes needed here.
- Click "Transform" and select your WAV file.
- That's all.
- You will find up to 33 RAW files in your folder. (If WAV is larger, the rest is truncated)
- "Transform Folder" is not useful yet. It's just experimental.
- "Header" adds an AMSDOS header to each RAW file.
- "As ASM" also generates ASM source code for each RAW part.
- "Store sample" also saves the complete RAW file as 1 sample file (up to 524k). (My experimental JavaCPC can import this by drag & drop)
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

arnoldemu

#42
http://www.cpctech.org.uk/source/mltmde2.asm

New/Updated source
- This example shows multiple modes using the firmware. It is based on the code here:
http://www.cpctech.org.uk/source/multmode.asm

- However, sometimes one of the mode changes will not occur exactly at the time we expect, but is delayed by 8 lines.
This delay is caused by the keyboard scan.

The firmware doesn't scan the firmware always at the same time in a frame. It does scan the keyboard every 6 interrupts so that it is once per frame.

This example shows how to sync with the vsync (using firmware), and then use KL SCAN NEEDED to reset the keyboard scan so that it occurs when we want it to. Now our mode splits are accurate.

EDIT: Only works on 664/6128 because it uses firmware v1.1 functions.
Source updated with comment.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

arnoldemu

New source:

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

This shows how to do the most accurate mode-split with the firmware.

It uses an asynchronous express fast ticker event.

With this one, I can't even use MC SET MODE because the alternative register set is not setup for it, and also because it disables and then re-enables interrupts. So this time I had to look at the OS and work out where the information is stored.

Normally C' holds the byte we are interested in, but at this point A' actually stores it.
Also I must ensure the rom is paged in, but I mustn't remember this in A'.

Asynchronous express interrupts are the 2nd interrupt type to be processed. First is frame ticker (if vsync is active), otherwise these are the first interrupt type to be executed at other times. This function is about 8 or so scanlines ahead of the previous one and doesn't get altered by the keyboard scanning AND it works on 464, 664 and 6128.

But to make it work I have to hit the hardware direct and make sure I setup the alternative register set correct, otherwise the firmware will crash.

Enjoy my journey into the OS rom and the results ;)

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

arnoldemu

New source:

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

This shows how to draw a 6x8 pixel font in mode 1 using the firmware.
It can be slow, but it works.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

arnoldemu

Quote from: arnoldemu on 14:08, 20 November 10
New source:

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

This shows how to draw a 6x8 pixel font in mode 1 using the firmware.
It can be slow, but it works.
And now the version without the firmware:

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

This does some manipulation of the screen pixels to draw and mask the chars.
This example also shows how you can write text to the screen *without* the firmware and using your own pixel data.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

AMSDOS

#46
arnoldemu wrote:

And now the version without the firmware:

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

This does some manipulation of the screen pixels to draw and mask the chars.
This example also shows how you can write text to the screen *without* the firmware and using your own pixel data.


Just wondering if this version of the program is supposed to return the user back to BASIC?

EDIT: Oh I see you're looping "l1" onto itself!  ;)  Change it to ret and your back in BASIC!  :)  Only the non-firmware version and firmware versions vary quite significantly cause the Firmware version alters the text so it still active once the program exits!  I couldn't see a lot of difference speed wise between both of these program, though I presume it would become more apparent the more you throw more 'text' at these routines!

* 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

arnoldemu

Quote from: CP/M User on 23:03, 20 November 10
arnoldemu wrote:

And now the version without the firmware:

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

This does some manipulation of the screen pixels to draw and mask the chars.
This example also shows how you can write text to the screen *without* the firmware and using your own pixel data.


Just wondering if this version of the program is supposed to return the user back to BASIC?

EDIT: Oh I see you're looping "l1" onto itself!  ;)  Change it to ret and your back in BASIC!  :)  Only the non-firmware version and firmware versions vary quite significantly cause the Firmware version alters the text so it still active once the program exits!  I couldn't see a lot of difference speed wise between both of these program, though I presume it would become more apparent the more you throw more 'text' at these routines!
Both pieces of code were actually made for another game which I am helping with.
Some other people are making it, but I offered some help. Not sure when this game will be released.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

redbox

Quote from: arnoldemu on 11:47, 22 November 10
Both pieces of code were actually made for another game which I am helping with.
Some other people are making it, but I offered some help. Not sure when this game will be released.

A Spectrum conversion?

The font looks very Speccy and also you're converting 1-bit per pixel graphics  ;)

AMSDOS

arnoldemu wrote:

Both pieces of code were actually made for another game which I am helping with.
Some other people are making it, but I offered some help. Not sure when this game will be released.


Always good to have a different font when it comes to games!  ;D

This article on Screen Squashing (which is older than my 6128  ;) ) always comes to mind when I think of articles on Character Sets:

http://cpcwiki.eu/imgs/7/78/Amstrad_Computer_User8504_020.jpg
http://cpcwiki.eu/imgs/3/3b/Amstrad_Computer_User8504_021.jpg
http://cpcwiki.eu/imgs/4/4b/Amstrad_Computer_User8504_022.jpg
http://cpcwiki.eu/imgs/5/5e/Amstrad_Computer_User8504_025.jpg

* 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

Powered by SMFPacks Menu Editor Mod