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

0 Members and 1 Guest are viewing this topic.

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: 1985
  • Likes Given: 4650
Re: ASM source code
« Reply #75 on: 20:49, 01 March 11 »
Well, it like the simple solution, usually it's the most efficient and therefore best. In my progs if works all fine. But we must separate two things here. a) to omit flickering b) to reduce flickering.
And I can only warn to use too complex strategies, they usually make it too slow. As Kolumbus alrady sayd: To be genious means to keep it simple. And like my old dad sayd: Everybody can make it complex. I always keep this things in mind.
Finally there will be one perfect strategy for every kind of resolution (x, y) and way of using split screens / overscan or just 16 K V-RAM.
 
 
Edit: I implicate that sprites are erased directly before they are redrawn, anything else makes no sense. To use erase/draw scanline cycles again cost too much time IHMO.
« Last Edit: 20:52, 01 March 11 by TFM/FS »
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2283
  • Likes Given: 3478
Re: ASM source code
« Reply #76 on: 11:27, 02 March 11 »
Well, it like the simple solution, usually it's the most efficient and therefore best. In my progs if works all fine. But we must separate two things here. a) to omit flickering b) to reduce flickering.
And I can only warn to use too complex strategies, they usually make it too slow. As Kolumbus alrady sayd: To be genious means to keep it simple. And like my old dad sayd: Everybody can make it complex. I always keep this things in mind.
Finally there will be one perfect strategy for every kind of resolution (x, y) and way of using split screens / overscan or just 16 K V-RAM.
 
 
Edit: I implicate that sprites are erased directly before they are redrawn, anything else makes no sense. To use erase/draw scanline cycles again cost too much time IHMO.
I agree that complex methods can make it slow.

Well let me be a student and learn ;)
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2283
  • Likes Given: 3478
Re: ASM source code
« Reply #77 on: 11:30, 02 March 11 »
New sources:

http://www.cpctech.org.uk/source/plot1.asm
http://www.cpctech.org.uk/source/plot2.asm
  http://www.cpctech.org.uk/source/plot3.asm
  http://www.cpctech.org.uk/source/plot4.asm
 
These examples show how to plot a pixel.
Each gets more and more low level, so you can see how the firmware functions work and also how to access pixels on the screen.

plot1.asm uses graphics functions to plot a pixel and works in any mode and with upper rom enabled/disabled. (GRA PLOT ABSOLUTE)

plot2.asm uses screen functions to plot a pixel and also works in any mode with upper rom enabled/disabled. (SCR DOT POSITION, SCR PIXELS, SCR INK ENCODE)

plot3.asm uses less screen functions to plot a pixel, works in any mode, but not with upper rom enabled. (SCR DOT POSITION, SCR INK ENCODE)

plot4.asm uses less screen functions, is now for mode 0, and doesn't work with upper rom enabled.
(SCR DOT POSITION)


EDIT1: These examples are not complete. Complete examples will be uploaded later today.
EDIT2: Samples complete and uploaded.
EDIT3:

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

plot4.asm example for mode 1.


  http://www.cpctech.org.uk/source/plot4m2.asm
 
  plot4.asm example for mode 2.
« Last Edit: 23:09, 02 March 11 by arnoldemu »
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.939
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1161
  • Likes Given: 1931
Re: ASM source code
« Reply #78 on: 12:08, 03 March 11 »
Interesting the number of ways you can Plot onscreen!  :-[
 
 :-[  Of course I've been doing some work with GRA PLOT ABSOLUTE and forgot about having this one huge routine.  ???
 
Code: [Select]
;; Tag Plot in Assembly

  ORG &4000
 
  ld a,1
  call &bc0e
  ld b,64              ;; Number of times to loop
  ld de,data_xpos      ;; Load Coordinate Position into DE
  ld hl,data_ypos      ;; Load Coordinate Position into HL
  ld (adrxpos),de
  ld (adrypos),hl      ;; Store address of data
  push hl
  ld hl,data_color
  ld (addrcolor),hl
  pop hl

.loop         ;; Begin of Loop
   push hl
   push af
   ld hl,(addrcolor)
   ld a,(hl)
   call do_color
   pop af
   pop hl
   
   ld de,(adrxpos)     ;; Get contents of address of Data
                       ;; into DE
   inc de
   inc de              ;; Increase this by 2 data is 2 bytes in size
   ld (adrxpos),de     ;; Put this new address into address of data
   ld hl,(adrypos)     ;; Put address of ypos into hl
   inc hl
   inc hl              ;; Increase this by 2 same as DE
   ld (adrypos),hl     ;; Put this new address into address of data
   push bc             
   call do_plot        ;; Call this routine
   pop bc
 
   djnz loop           ;; Go back if B is greater than 0
   ret                  ;; Otherwise Exit
 
.do_color
  call &bbde
  ld hl,(addrcolor)
  inc hl
  ld (addrcolor),hl
  ret
 
.do_plot
 
  ld b,(hl)            ;; Store Contents of Lower HL (YPOS Data) into B
  inc hl               ;; Increase address of HL
  ld c,(hl)            ;; Store Contents of Upper HL (YPOS Data) into C
  ld hl,ypos           ;; Get Lower address of HL
  ld (hl),b            ;; And put value of B into it
  inc hl               ;; Increase this by 1
  ld (hl),c            ;; Now put value of C into it
 
  ;; What this has effecively done is move the contents
  ;; of ypos in particular, from one memory location to
  ;; another fixed location, for where the data can go
  ;; into the registers & then do a call to Plot Absolute
  ;; (&BBEA). I used to try doing this while moving the
  ;; address (e.g. Get contents of first xpos & ypos,
  ;; then move onto the second), course it maybe possible,
  ;; but I found this much easier.
 
  ex de,hl        ;; Exchange Contents of DE & HL
  ld b,(hl)            ;; Put Contents of HL (which was DE) into B
  inc hl               ;; Increase HL by 1
  ld c,(hl)            ;; Put that into C
  ld hl,xpos           ;; Get address of xpos
  ld (hl),b           
  inc hl
  ld (hl),c            ;; Put contents into it
 
  ;; This is really just the same as above apart from getting the
  ;; address of xpos, I left it with this, instead of trying to
  ;; Poke my own program (by replacing YPOS address with XPOS). 
 
  ld de,(xpos)         ;; So with all the data being at XPOS &
  ld hl,(ypos)         ;; YPOS, I can do a call for Plot Absolute
  call &bbea
  ret
 
;; Data Areas
 
.xpos  defw 0          ;; Section where XPOS & YPOS goes
.ypos  defw 0
.adrxpos defw 0        ;; This is the address of the data for XPOS
.adrypos defw 0        ;; Same as Above except for YPOS
 
.data_xpos
 defw 0                ;; Leave this line here
 defw 0,2,4,6,8,10,12,14 ;; Sample Data (XPOS)
 defw 0,2,4,6,8,10,12,14
 defw 0,2,4,6,8,10,12,14
 defw 0,2,4,6,8,10,12,14
 defw 0,2,4,6,8,10,12,14
 defw 0,2,4,6,8,10,12,14
 defw 0,2,4,6,8,10,12,14
 defw 0,2,4,6,8,10,12,14
 
.data_ypos
 defw 0                ;; Leave this line alone
 defw 0,0,0,0,0,0,0,0  ;; Sample Data (YPOS)
 defw 2,2,2,2,2,2,2,2
 defw 4,4,4,4,4,4,4,4
 defw 6,6,6,6,6,6,6,6
 defw 8,8,8,8,8,8,8,8
 defw 10,10,10,10,10,10,10,10
 defw 12,12,12,12,12,12,12,12
 defw 14,14,14,14,14,14,14,14
 
.data_color
 defb 1,1,0,1,0,1,1,0
 defb 0,3,3,3,3,3,0,0
 defb 0,0,2,2,2,0,0,0
 defb 0,0,2,2,2,0,0,0
 defb 0,0,2,2,2,0,0,0
 defb 0,0,2,2,2,0,0,0
 defb 0,0,2,2,2,0,0,0
 defb 0,0,0,1,0,0,0,0
 
.addrcolor
 defw 0

Purpose?  It's clearly not ideal for Sprite Handling, though it could be made to handle large fixed images without loading in 17k Screens perhaps. Maybe possible to reduce the size of this routine/program, by reducing the reoccuring xpos & ypos values. Otherwise it's simply another routine for the dust pile!  8)
* 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.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2283
  • Likes Given: 3478
Re: ASM source code
« Reply #79 on: 12:40, 03 March 11 »
Interesting the number of ways you can Plot onscreen!  :-[
Well each goes lower and lower level, so that the final one (not finished yet), calcs screen address of pixel, does all the masking and plotting itself.
 
Purpose?  It's clearly not ideal for Sprite Handling, though it could be made to handle large fixed images without loading in 17k Screens perhaps. Maybe possible to reduce the size of this routine/program, by reducing the reoccuring xpos & ypos values. Otherwise it's simply another routine for the dust pile!  8)

I see, drawing a sprite or image using GRA PLOT ABSOLUTE. Interesting idea, and I am sure this works well with cpm.

BTW, I am happy to host any routines on my website in the source section.
So you don't have to let them disapear ;)
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.939
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1161
  • Likes Given: 1931
Re: ASM source code
« Reply #80 on: 11:08, 04 March 11 »
arnoldemu wrote:

Well each goes lower and lower level, so that the final one (not finished yet), calcs screen address of pixel, does all the masking and plotting itself.

The way the experts would make it!  ;D
 
Quote
Purpose?  It's clearly not ideal for Sprite Handling, though it could be made to handle large fixed images without loading in 17k Screens perhaps. Maybe possible to reduce the size of this routine/program, by reducing the reoccuring xpos & ypos values. Otherwise it's simply another routine for the dust pile!  8)

I see, drawing a sprite or image using GRA PLOT ABSOLUTE. Interesting idea, and I am sure this works well with cpm.

Well it was only a part of another routine I had made ages ago (which I think I posted on this forum earlier - to see if it could be improved). Originally the idea was to see how this "Tag Plot" routine would perform as a sprite routine. Not really up to it - as demonstrated from my original Bouncing Ball program which is on my website. There would be some marginal improvement if all that code was in assembly, though I can still see some delay in it - obviously not really meant for plotting an image around the screen, it works (including in CP/M) great if you love slow motion!  ;D 
SCR HORIZONTAL on the other hand is look a bit more promising in terms of display rate time, won't really know how well it works moving things around til I get around to it, at the moment I'm studying the last program I made and writing in the what facts and figures I can code in to make an 8x8 move around. It probably won't ever be as fast as a true sprite routine, though if it's reasonible I may find something for it!

BTW, I am happy to host any routines on my website in the source section.
So you don't have to let them disapear ;)


These routines I come up with are usually work-in-progress. I don't mind whoever wants them can most certainally have them, it's Public Domain at best I reckon!  ;D  This one I just posted I can certainally make it better  by include a Double-byte Loop which would allow for larger images and make it work better that way. By only concern is allowing for larger images will blowout the number of co-ordinate positions, really needs to be written so the table would go:
 
x: 0,2,4,6,8,10,12,14
y: 0,2,4,6,8,10,12,14
 
Increment y from 0 to 2 when x has plotted out 14 and resetting x to 0 - thus producing the next line for x to plot the points along the y axis.
* 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.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2283
  • Likes Given: 3478
Re: ASM source code
« Reply #81 on: 11:24, 07 March 11 »
Updated sources:

http://www.cpctech.org.uk/source/pscrlvrt.asm
http://www.cpctech.org.uk/source/pscrlhrz.asm
(Added some chars to screen so scroll effect is seen better over whole screen)

http://www.cpctech.org.uk/source/hardscrl.asm
(Now checks for lower case chars for keys and has chars over the screen so effect is better)

http://www.cpctech.org.uk/source/scrlhrz.asm
(Chars over the screen to see effect better, checks for lower case chars for keys, fixed R3 scrolling in both directions)

New source:

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

Demonstrates a lot of the scr functions, including SCR NEXT BYTE, SCR PREV BYTE, SCR NEXT LINE, SCR PREV LINE, SCR GET LOCATION, RAM LAM.
This moves a sprite (flickering) over a background.
It uses the firmware functions to read/write the screen in a way that works with upper rom enabled.
You can activate 2 different read functions and 2 different write functions.

One read using indirections (but the lower rom must be enabled for this to work), and one using RAM LAM.
And 2 different write functions (one writing direct, another using scr pixels).

New test source:

http://www.cpctech.org.uk/source/plusscrl.asm
Mid-line screen scrolling on plus

I need to test on a real +, I am not sure full scrolling would be possible.
But may be useful for some effects.


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

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2283
  • Likes Given: 3478
Re: ASM source code
« Reply #82 on: 22:32, 21 March 11 »
New source:

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

Memory check code used in Batman Forever demo.

To use:
1. call memcheck
2. call mem_check_contig_64_blocks
A register is the first configuration where there are 64k pages side by side that can be used. So you can access the ram with one base page.

mem_unique_configs is the list of page configurations that are valid and can be used.
Up to 512k dk'tronics compatible ram is supported by this code.

So for example, you can use the ram of a dk'tronics silicon disk on a 464 and the code will still detect as having enough ram. It will then give you the list of blocks (e.g. starting from cc).
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2283
  • Likes Given: 3478
Re: ASM source code
« Reply #83 on: 11:31, 22 March 11 »
More source will come soon, including some test code, and with the musical loader I'll write up all the things I discovered and worked out in order to make it work.

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

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2283
  • Likes Given: 3478
Re: ASM source code
« Reply #84 on: 19:25, 24 April 11 »
New source:

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

Software scrolling the screen using the firmware and SCR SW ROLL.
This also demonstrates how you update a line of the screen, depending on the direction scrolling to maintain the scroll effect.
The scroll is in char sized increments (8 lines) and is only up and down.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2283
  • Likes Given: 3478
Re: ASM source code
« Reply #85 on: 19:38, 24 April 11 »
New source:

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


Hardware scrolling the screen using the firmware and SCR HW ROLL.
This also demonstrates how you update a line of the screen, depending on the direction scrolling to maintain the scroll effect.
The scroll is in char sized increments (8 lines) and is only up and down.

The effect is poor, clearing the line and drawing the chars takes a long time using firmware, so you can't see the power of hardware scrolling, but demonstrates this function.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2283
  • Likes Given: 3478
Re: ASM source code
« Reply #86 on: 23:34, 28 April 11 »
Two new sources:

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

This example uses KM SET EXPAND and KM SET TRANSLATE to associate a string with a key. e.g. when you press F1 it could print "|DISC<CR>" in basic. Same kind of functionality as KEY DEF but in asm.

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

This example autotypes a string in basic. It uses a frame flyback interrupt, it returns each char of a string using KM CHAR RETURN, it then monitors if that char has been read yet (so this locks it to firmware 1.1 at this time - CPC6128, Plus). Typing is not as fast as Markus has been able to do with his emu ;)

Both came about after discussion with somebody about autotyping strings in order to autoboot a program.
So here we go.

NOTE: KM CHAR RETURN is used to put 1 ASCII char into the keyboard buffer. However, when it's read, it is not decoded, so you can't assign it a string with KM SET EXPAND and expect it to display a whole string. Firmware just returns the char you gave it. ;)

« Last Edit: 23:10, 05 June 11 by arnoldemu »
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2283
  • Likes Given: 3478
Re: ASM source code
« Reply #87 on: 23:29, 05 June 11 »
Arrgh. I did another edit. And I thought I had just quoted  :laugh:

EDIT: Is there a way for me to revert an  edit I made to my own message?

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

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.939
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1161
  • Likes Given: 1931
Re: ASM source code
« Reply #88 on: 03:01, 06 June 11 »
Arrgh. I did another edit. And I thought I had just quoted  :laugh:

EDIT: Is there a way for me to revert an  edit I made to my own message?

Google Cache?
 
I presume it's this post:
 
Quote
New source:

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

Double buffering using the firmware.
Demonstrates the firmware functions MC SCREEN OFFSET and SCR SET POSITION.
Yes, even with the firmware you can double buffer graphics to make them flicker free if you want.
* 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.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2283
  • Likes Given: 3478
Re: ASM source code
« Reply #89 on: 11:12, 06 June 11 »
New source:

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

Double buffering using the firmware.
Demonstrates the firmware functions MC SCREEN OFFSET and SCR SET POSITION.
Yes, even with the firmware you can double buffer graphics to make them flicker free if you want.

(Thanks it was this one)
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline redbox

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.788
  • Country: gb
    • redbox
  • Liked: 407
  • Likes Given: 287
Re: ASM source code
« Reply #90 on: 12:00, 06 June 11 »
Double buffering using the firmware.


Fantastic, thanks for this.

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2283
  • Likes Given: 3478
Re: ASM source code
« Reply #91 on: 11:34, 05 July 12 »
Please can we sticky this topic?
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline Gryzor

  • Administrator
  • 6128 Plus
  • *****
  • Posts: 17.028
  • Country: gr
  • CPC-Wiki maintainer
    • CPCWiki
  • Liked: 4093
  • Likes Given: 7408
Re: ASM source code
« Reply #92 on: 11:37, 05 July 12 »
Please can we sticky this topic?


Sure, but (since I haven't followed it), what is it about? The title isn't super-explanatory...

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.939
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1161
  • Likes Given: 1931
Re: ASM source code
« Reply #93 on: 04:04, 08 September 12 »

Sure, but (since I haven't followed it), what is it about? The title isn't super-explanatory...


ASM is shorthand for ASseMbly which usually reflects the 'asm' extension for the source code. Sometimes people might use a different extension (e.g. '.Z80'), if they want to emphasise which form of CPU their using (useful when you're dealing with a site which deals with several different platforms).


Normally if I want to look at something though I visit the 'Unofficial Amstrad WWW Resource' site though.  :D
* 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 TotO

  • 6128 Plus
  • ******
  • Posts: 4.011
  • Country: fr
    • ?area=showdonations;u=4
  • Liked: 3109
  • Likes Given: 1889
Re: ASM source code
« Reply #94 on: 09:18, 08 September 12 »
I though that Gryzor did not ask about the mean of ASM but about the goal/content of the topic, to know how to "stick it". :)
« Last Edit: 14:45, 08 September 12 by TotO »
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2283
  • Likes Given: 3478
Re: ASM source code
« Reply #95 on: 11:30, 08 September 12 »

Sure, but (since I haven't followed it), what is it about? The title isn't super-explanatory...
In this topic I, and others,  have posted links to various example programs written in z80 assembly language.
Some of these show how to use firmware functions, others to draw sprites.

I requested the sticky because I think others would be interested to look through the posts to help them learn coding on the cpc.

If you could change the topic title to "Example Z80 assembly programs" that would be great too.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline Gryzor

  • Administrator
  • 6128 Plus
  • *****
  • Posts: 17.028
  • Country: gr
  • CPC-Wiki maintainer
    • CPCWiki
  • Liked: 4093
  • Likes Given: 7408
Re: ASM source code
« Reply #96 on: 12:19, 13 September 12 »
@TotO, thanks, that's indeed what I was wondering about
@Arnoldemu, sure, will do it right away :)

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.939
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1161
  • Likes Given: 1931
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #97 on: 11:29, 29 October 12 »

This is my most refined example I've made which is using GRA LINE ABSOLUTE to draw a series of lines (from the example provided) from a loop. I made an earlier example (which I might of posted elsewhere), though in this one I've setup 2 address pointers which points to the data I want to display in memory. My earlier example was taking the data from one spot, and moving it into another area and GRA LINE ABSOLUTE was accessing it from there. That method worked, though seemed to be a run around approach which I felt could be improved. This is the result.


Code: [Select]

;; Draw loop  in Assembly
;; CP/M User


ORG &4000 ;; This routine can go almost anywhere
 
;; Initialiation stuff


;; ld a,1
;; call &bc0e ;; SCR SET MODE, Routine will work in any mode which is set.


ld a,1
call &bbde ;; GRA SET PEN (PEN 1)


ld de,100 ;; xpos position to start at
ld hl,100 ;; ypos position to start at


;; Changing these values will change where and how image is to be drawn.


call &bbc0 ;; GRA MOVE ABSOLUTE


;; Setup size of the Loop with points to plot


ld b,4 ;; number of points to loop for image


.loop ;; The main loop


ld hl,(adrypos) ;; Address contents which points to image data for ypos goes into HL


ld e,(hl) ;; \
inc hl ;; - Contents of HL which is ypos data (16bit number) goes into DE
ld d,(hl) ;; /


ex de,hl ;; That information (ypos data) needs to go into HL register


push hl ;; But I need to protect that information so I can use HL.


ld hl,(adrxpos) ;; Address contents which points to image data for xpos goes into HL


ld e,(hl) ;; \
inc hl ;; - The same process now happens for xpos data (16bit number) going into DE
ld d,(hl) ;; /


pop hl ;; I can now restore that ypos data back into HL...


push bc ;; ...though I need to protect the loop counter.


call &bbf6 ;; GRA LINE ABSOLUTE, Entry: HL = y-coordinate, DE = x-coordinate
;; Exit: AF, BC, DE & HL corrupt.


pop bc ;; Restore loop counter.


ld hl,(adrxpos) ;; \
inc hl ;; - This moves address pointer for xpos to the following address & stores it.
inc hl ;; - Because 16bit data is being used, HL is incremented twice.
ld (adrxpos),hl ;; /


ld hl,(adrypos) ;; \
inc hl ;; - And the same thing applies for the address pointer for ypos data.
inc hl ;; - And again 16bit data is used.
ld (adrypos),hl ;; /


djnz loop ;; If loop counter hasn't being reached,
;; loop counter is decreased by 1 until B = 0.
;; The following address pointer will then be used.


ld hl,data_xpos ;; \
ld (adrxpos),hl ;; :
;; - Once loop is finished, the data points for xpos & ypos needs to be restored.
ld hl,data_ypos ;; :
ld (adrypos),hl ;; /


ret ;; Returns to BASIC (if called from there).


.adrxpos


defw data_xpos


.adrypos


defw data_ypos


.data_xpos


defw 100,200,200,100,0 ;; Standard graphic points to draw for xpos.


.data_ypos


defw 200,150,100,100,0 ;; Standard graphic points to draw for ypos.
* 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 TotO

  • 6128 Plus
  • ******
  • Posts: 4.011
  • Country: fr
    • ?area=showdonations;u=4
  • Liked: 3109
  • Likes Given: 1889
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #98 on: 14:14, 29 October 12 »
The pseudo random number generator from the cpcrslib for SDCC.
Look simple and efficient, as shown into the game named Totems.

Code: [Select]
_cpc_Random::
   LD A,(#valor_previo)
   LD L,A
   LD A,R
   ADD L
   LD (#valor_previo),A
   LD L,A
   LD H,#0  ; value return in HL
   RET
valor_previo:
   .db #0xFF
« Last Edit: 14:16, 29 October 12 by TotO »
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

Offline SyX

  • 6128 Plus
  • ******
  • Posts: 1.137
  • Country: br
  • Liked: 1143
  • Likes Given: 1879
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #99 on: 16:04, 03 November 12 »
A few years ago, i put a lot of snippets in this thread of the spanish forum, feel free to use them, and if somebody needs english comments, only ask :)