Author Topic: Example Z80 assembly programs (was:ASM source code)  (Read 75804 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
New source:

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

Software scroll using LDI for copying the scroller.
Mode 1 font (2 bytes wide and 16 lines tall).

I will add to this thread as I release my example sources.
« Last Edit: 12:20, 13 September 12 by Gryzor »
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 #1 on: 11:16, 04 April 10 »
New source:

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

A   simple single line scrolling horizontal split raster.
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 #2 on: 21:35, 04 April 10 »
New source:


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

Example shows how to load your own code into the multiface 2 ram. When the Stop button is pressed your code is executed. The multiface 2 menu is not shown.
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 #3 on: 23:44, 04 April 10 »
New source

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

Horizontal message scroller. Uses hardware scroll (crtc reg 12 and 13).
Note: Code is not optimised, it is meant for example for others to learn.
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 #4 on: 23:29, 19 April 10 »
New source

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

Source shows the type of sprites used in Mission Genocide, Ghosts and Goblins, Bubble Bobble, Ghouls and Ghosts.

Sprites are 3 colours (pen 0 is transparent). Background is 4 colours.
Sprites drawn using logical-OR and erased using logical-AND.

These are also known as "bitplane" sprites.
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: ASM source code
« Reply #5 on: 20:05, 21 April 10 »
Source shows the type of sprites used in Mission Genocide, Ghosts and Goblins, Bubble Bobble, Ghouls and Ghosts.

That's a really cool example, will have a play around with it.

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.332
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2247
  • Likes Given: 3477
Re: ASM source code
« Reply #6 on: 23:52, 21 April 10 »
That's a really cool example, will have a play around with it.

:) remember it is not optimised!

The sprite drawing and erase loops could be unrolled to speed it up for example.
Also i use the firmware for checking keys pressed, this could be changed for direct hardware reading.
So there is scope to improve it.

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 #7 on: 23:54, 21 April 10 »
New source:

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

An example that shows a mode 0 sprite over a background. Pen 0 of sprite is transparent, leaving 15 pens for use with the sprite.
Background can use any of the 16 colours. Sprite is masked when it is drawn to screen.
Background behind sprite is stored in a buffer.

Sprite x movement is by the byte (so 2 pixels at a time in X).
Sprite y movement is by the line (1 pixel in Y).

Again, the code is not optimised.

Code also shows use of a 256-byte aligned mask table, how to create it and how to use it to mask the sprite.

NOTE: Background from internet at a site that claims that the picture is free for use.
Sprite is my own ;)
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

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: ASM source code
« Reply #8 on: 23:55, 21 April 10 »
Cool...
Your asm codes really help me to improve JavaCPC's Z80 assembler ;)
The source for rotosprites compiles well after I found a missing command ;)
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
Re: ASM source code
« Reply #9 on: 23:58, 21 April 10 »
Cool...
Your asm codes really help me to improve JavaCPC's Z80 assembler ;)
The source for rotosprites compiles well after I found a missing command ;)

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

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: ASM source code
« Reply #10 on: 23:58, 21 April 10 »
Funny:
Also the roto sprite in example before and now this disappear in upper half of screen?
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
Re: ASM source code
« Reply #11 on: 00:01, 22 April 10 »
Funny:
Also the roto sprite in example before and now this disappear in upper half of screen?
Indeed.
I wait for vsync and first erase the sprite, then I check for keyboard to decide where new sprite coords should be then I draw sprite in new position.
But by this time monitor refresh has gone too far, so either you see no sprite (so time when sprite has been erased and I am checking keyboard), or if you are lucky you see the sprite in time  :P

For example code it works if you move the sprite into the correct place  :P

Well there are ways to fix this: 1. use double buffer 2. erase and draw sprite in same routine, erase a line, draw the line, erase a line, draw the line etc.
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 #12 on: 23:47, 23 April 10 »
New source:

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

This example is for Markus ;)

Shows:
1. ASM version of SPEED KEY 1,1 to speed up key presses (thanks Markus for suggesting it)
2. Only drawing sprite when it has moved (thanks again Markus for suggesting it). The sprite does flicker when moved.
3. Masked mode 1 sprites
4. Pre-shifted sprites. There are 4 sprites used here, each shifted by one more pixel than the other. This is done to move the sprite pixel by pixel.
5. 16-bit X coordinates for positioning sprite on screen
6. Nice background and nice smiley sprite with it's tongue sticking out (I am sure I read that Markus likes these smileys ;) )
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

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: ASM source code
« Reply #13 on: 00:46, 24 April 10 »
Nice example.
Managed to fix another bug thanks your code ;)

But your code is bad!
Compile, run it and move sprite up! (Reset)
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 Ynot.zer0

  • CPC6128
  • ****
  • Posts: 293
  • Country: gb
  • Liked: 23
  • Likes Given: 63
Re: ASM source code
« Reply #14 on: 13:00, 24 April 10 »
the disappearing sprite  :P

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.332
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2247
  • Likes Given: 3477
Re: ASM source code
« Reply #15 on: 23:14, 25 April 10 »
Nice example.
Managed to fix another bug thanks your code ;)

But your code is bad!
Compile, run it and move sprite up! (Reset)
possibly. I found a bug where pre-shifted sprites overrun the buffer.
Yeah it resets near the top.. so... ?
I'll fix it later ;)

EDIT: New version of code has been uploaded that fixes the bug that Markus reported.
« Last Edit: 11:54, 27 April 10 by arnoldemu »
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: ASM source code
« Reply #16 on: 11:13, 27 April 10 »
the disappearing sprite  :P

Proof. Of. Concept.

Offline Ynot.zer0

  • CPC6128
  • ****
  • Posts: 293
  • Country: gb
  • Liked: 23
  • Likes Given: 63
Re: ASM source code
« Reply #17 on: 13:03, 27 April 10 »
..and very nice PoCs these samples are too.  I'm learning quite a lot from them at the moment.

With the latest code update
buffer_size equ sprite_height*(sprite_width+1)
;; a buffer to store screen behind sprite

sprite_background:
defs buffer_size               <<<<<<<<<<<<<<<<Assemble error here

I found that for some reason it would not compile if referencing sprite_height; but if you replace it with the numeric value it works:

defs 64*sprite_width+1

I'm curious; can anyone explain why?

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: ASM source code
« Reply #18 on: 13:19, 27 April 10 »
buffer_size equ sprite_height*(sprite_width+1)
;; a buffer to store screen behind sprite

sprite_background:
defs buffer_size               <<<<<<<<<<<<<<<<Assemble error here

Which assembler did you use? (JavaCPC's assembler parses the mathematics correct here. (In progress...))
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 Ynot.zer0

  • CPC6128
  • ****
  • Posts: 293
  • Country: gb
  • Liked: 23
  • Likes Given: 63
Re: ASM source code
« Reply #19 on: 13:31, 27 April 10 »
winape 2.0 alpha 17

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.332
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2247
  • Likes Given: 3477
Re: ASM source code
« Reply #20 on: 13:36, 27 April 10 »
..and very nice PoCs these samples are too.  I'm learning quite a lot from them at the moment.

With the latest code update
buffer_size equ sprite_height*(sprite_width+1)
;; a buffer to store screen behind sprite

sprite_background:
defs buffer_size               <<<<<<<<<<<<<<<<Assemble error here

I found that for some reason it would not compile if referencing sprite_height; but if you replace it with the numeric value it works:

defs 64*sprite_width+1

I'm curious; can anyone explain why?
Sorry I didn't check my update with winape.
I did check most of the others.
for winape you probably need to do this:

preshifted_width equ sprite_width+1
buffer_size equ sprite_height*preshifted_width

defs buffer_size


I normally use pasmo for my code because like javacpc it has an assembler that evaluates the mathematical expressions and allows you to bracket them.

If I have time, I'll correct it for winape.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

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: ASM source code
« Reply #21 on: 13:42, 27 April 10 »
You can try the mathparser I am using in JavaCPC's assembler here:
http://cpc-live.com/calc/

Simply enter what you want to calculate in the upper text window.
e.g. 20*(40+1)
It also accepts binary input like %10110111*15
« Last Edit: 13:49, 27 April 10 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 Executioner

  • Supporter
  • 6128 Plus
  • *
  • Posts: 783
  • Country: au
  • WinAPE Developer
    • WinAPE
  • Liked: 391
  • Likes Given: 60
Re: ASM source code
« Reply #22 on: 06:07, 28 April 10 »
I normally use pasmo for my code because like javacpc it has an assembler that evaluates the mathematical expressions and allows you to bracket them.

This was never done in WinAPE simply because it wouldn't be Maxam compatible any longer, and would break lots of existing assembler code. I might include it as an option in the next release though.

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: ASM source code
« Reply #23 on: 11:32, 28 April 10 »
I have an option in my assembler.
You can select left-to-right calculation (default, like maxam) or exact math parsing (allows brackets etc...)
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
Re: ASM source code
« Reply #24 on: 23:52, 28 April 10 »
Updated source:

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

Now builds with Winape assembler.

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 :)
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource