News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

Example Z80 assembly programs (was:ASM source code)

Started by arnoldemu, 08:59, 04 April 10

Previous topic - Next topic

0 Members and 3 Guests are viewing this topic.

arnoldemu

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

arnoldemu

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

arnoldemu

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

arnoldemu

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

arnoldemu

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

redbox

Quote from: arnoldemu on 21:29, 19 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.

arnoldemu

Quote from: redbox on 18:05, 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

arnoldemu

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

Devilmarkus

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

arnoldemu

Quote from: Devilmarkus on 21: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 ;)

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

Devilmarkus

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

arnoldemu

Quote from: Devilmarkus on 21:58, 21 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

arnoldemu

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

Devilmarkus

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

Ynot.zer0

the disappearing sprite  :P

arnoldemu

#15
Quote from: Devilmarkus on 22:46, 23 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.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

redbox


Ynot.zer0

..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?

Devilmarkus

Quote from: ynot.zer0 on 11:03, 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

Ynot.zer0

winape 2.0 alpha 17

arnoldemu

Quote from: ynot.zer0 on 11: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?
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

Devilmarkus

#21
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
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

Executioner

Quote from: arnoldemu on 11:36, 27 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.

Devilmarkus

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

arnoldemu

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

Powered by SMFPacks Menu Editor Mod