News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

this in asm : ((ny / 8) * 80) + ((ny % 8) * 2048) + (nx / 2)+ #c000

Started by funkheld, 22:05, 16 July 20

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AMSDOS

I altered the routine used in Fast Plot to Calculate the Screen Address, I don't know if there's bits of assembly within that, which aren't relevant for calculating the Screen Address, otherwise the routine works.




org &8000


ld hl,0
ex hl,de
ld hl,0




.caline
;; input: de = x (0..79), hl = y (0..199)
;; exit:  hl = screen address


ld a,l ;; a = lowbyte y
and 7 ;; isolate Bit 0..2
ld h,a ;; =y mod 8 to h
xor l ;; a = bit 3..7 of y
ld l,a ;; = (y\8)*8 to l
ld c,a ;; store in c
ld b,&60 ;; b = &c0\2 = Highbyte Screenstart\2


add hl,hl ;; hl * 2
add hl,hl ;; hl * 4
add hl,bc ;; + bc = startaddress
add hl,hl ;; of the raster line


add hl,de ;; hl = screen address
ret


* 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

funkheld


I sometimes have the feeling that certain system routines cause sdcc to shut down the system? ::)

greeting

reidrac

My mind has been blown!  :o

Based on @AMSDOS code: 158 cycles; compared with my SDCC based version: 341 cycles.

And it works nicely!
Released The Return of Traxtor, Golden Tail, Magica, The Dawn of Kernel, Kitsune`s Curse, Brick Rick and Hyperdrive for the CPC.

If you like my games and want to show some appreciation, you can always buy me a coffee.

AMSDOS

Quote from: reidrac on 08:24, 19 July 20
My mind has been blown!  :o

Based on @AMSDOS code: 158 cycles; compared with my SDCC based version: 341 cycles.

And it works nicely!


The original Fast Plot Routine that this is based on was published in CPC Amstrad International with an article by Matthias Uphoff in 1989, it can be looked up on CPC-Rulez:
https://cpcrulez.fr/coding_src-list-fast-plot.htm


But it only worked in MODE 1, @Executioner converted it to MODE 0, all I did was remove the bitmasking required to allow the plotting and 'srl e' because Sprites are handled normally in bytes, so this won't handle perfect pixel animation, so maybe it would be better with 'srl e', so when e=0 or e=1 screen address = the same address, so perhaps that second position could be used for animated sprite.



Quote from: funkheld on 08:04, 19 July 20
I sometimes have the feeling that certain system routines cause sdcc to shut down the system? 


greeting


The danger is if variables are outside their intended values and the formula sends the graphic offscreen and somewhere which is sensetative or corrupting code. The firmware routines used to calculate the screen positions or next or previous lines, safely keeping it on the screen, they are slower though then calculating screen addresses, but prevent accidents from happening.
* 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

reidrac

Quote from: AMSDOS on 10:18, 19 July 20

The original Fast Plot Routine that this is based on was published in CPC Amstrad International with an article by Matthias Uphoff in 1989, it can be looked up on CPC-Rulez:
https://cpcrulez.fr/coding_src-list-fast-plot.htm


But it only worked in MODE 1, @Executioner converted it to MODE 0, all I did was remove the bitmasking required to allow the plotting and 'srl e' because Sprites are handled normally in bytes, so this won't handle perfect pixel animation, so maybe it would be better with 'srl e', so when e=0 or e=1 screen address = the same address, so perhaps that second position could be used for animated sprite.

I made some tweaks myself to better work with my codebase. I'm only interested in the address; this is used to draw sprites mostly.
Released The Return of Traxtor, Golden Tail, Magica, The Dawn of Kernel, Kitsune`s Curse, Brick Rick and Hyperdrive for the CPC.

If you like my games and want to show some appreciation, you can always buy me a coffee.

ronaldo

Quote from: reidrac on 16:57, 18 July 20
And the code that SDCC generates isn't that bad. I was looking to write that by hand but I made a mistake and I looked at the cpctelera code (that is brilliant, by the way); and I don't want to be "influenced" too much to risk breaking the licence or adding a dependency :D
If you want to use the code you are completely free to do so. We are deciding on moving CPCtelera to MIT/Apache license, and that is the most likely decision for CPCtelera 2.0. In the meantime, you could consider this post as a license permision. Even without it, we would never use the license to claim anything from other Amstrad authors. In fact, this is completely aligned with MIT/Apache license premises, and that's why we will be changing into it. We started with GPL because that was default on most of our projects to encourage further free&open software. But in the case of CPCtelera I think that's much more reasonably accomplished with the less restrictive licenses.

So, please, don't be afraid of breaking any license: the code is there to be used whenever you feel it may be of use for you. And of course, if anyone finds bugs, improvements or better ideas on how to do things, they are always welcome.

reidrac

Quote from: ronaldo on 18:22, 19 July 20
If you want to use the code you are completely free to do so. We are deciding on moving CPCtelera to MIT/Apache license, and that is the most likely decision for CPCtelera 2.0. In the meantime, you could consider this post as a license permision. Even without it, we would never use the license to claim anything from other Amstrad authors. In fact, this is completely aligned with MIT/Apache license premises, and that's why we will be changing into it. We started with GPL because that was default on most of our projects to encourage further free&open software. But in the case of CPCtelera I think that's much more reasonable accomplished with the less restrictive licenses.

So, please, don't be afraid of breaking any license: the code is there to be used whenever you feel it may be of use for you. And of course, if anyone finds bugs, improvements or better ideas on how to do things, they are always welcome.

Thank you, appreciated!

I think MIT is perfect for this type of library, I may release code too. Since Kistune's Curse I've been working on more generic code instead of custom for the project, and that may be reusable by someone else. I'm still using cpcrslib for keyboard/joystick, but I plan to write something a bit more minimalistic (I did it for the speccy and I'm happy with the result).

Anyway, it was a surprise finding that nice routine in CPC Wiki forum. I'm using it currently!
Released The Return of Traxtor, Golden Tail, Magica, The Dawn of Kernel, Kitsune`s Curse, Brick Rick and Hyperdrive for the CPC.

If you like my games and want to show some appreciation, you can always buy me a coffee.

funkheld

CPCtelera 2.0. ....... ;) ;) 

1.5  cpctelera is not even out yet.

what's with 2.0?



burns the licenses.
life is easier without licenses ...

roudoudou

Quote
burns the licenses.
life is easier without licenses ...



Thats the purpose of mit license  ;)
My pronouns are RASM and ACE

GUNHED

Quote from: roudoudou on 15:04, 17 July 20
you miss the point
(var/8)*80 is very different from var*10
i let you try with var=1 and var=2
You too.  :) In his formula, there are no brackets.
http://futureos.de --> Get the revolutionary FutureOS (Update: 2023.11.30)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.12.26)

roudoudou

Quote from: GUNHED on 08:57, 22 July 20
You too.  :) In his formula, there are no brackets.
I know you miss the point, it's useless to say it again  ;D
try with value=1 and value=2, see the difference
My pronouns are RASM and ACE

GUNHED

Quote from: roudoudou on 09:03, 22 July 20
I know you miss the point, it's useless to say it again  ;D
try with value=1 and value=2, see the difference

In his original post there were no brackets. See first post.
http://futureos.de --> Get the revolutionary FutureOS (Update: 2023.11.30)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.12.26)

roudoudou

Quote from: GUNHED on 09:05, 22 July 20
In his original post there were no brackets. See first post.
You are wrong. Check again and slowly the original post, maybe you will understand why you completly miss the point...

title has a computable formula with brackets
this in asm : ((ny / 8) * 80) + ((ny % 8) * 2048) + (nx / 2)+ #c000
post has a formula with 2 typos (this formula cant be computed because there is 2 brackets never closed), you may obviously guess it's wasn't copy/past then typos

((ny / 8 * 80) + ((ny % 8 * 2048) + (nx / 2)+ #c000
My pronouns are RASM and ACE

roudoudou

he removed 2 ending brackets because of smileys  ;D
now it's ok for you?
My pronouns are RASM and ACE

GUNHED

http://futureos.de --> Get the revolutionary FutureOS (Update: 2023.11.30)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.12.26)

roudoudou

Yeah, please Fix the formula in the first post  :P using CODE tag ( # icon )


My pronouns are RASM and ACE

funkheld

here in the forum the "(" and the ")" are not output correctly.

zhulien

jscompile POC with no optimisation for:



function main()
{
    var intA = ((ny / 8) * 80) + ((ny % 8) * 2048) + (nx / 2) + c000;
}


generates:




main:
   call main_constructor
   ret


main_constructor:
   ld hl, ny
   push hl
   ld hl, 8
   push hl
   call sys_div
   ld hl, 80
   push hl
   call sys_mult
   ld hl, ny
   push hl
   ld hl, 8
   push hl
   call sys_mod
   ld hl, 2048
   push hl
   call sys_mult
   call sys_add
   ld hl, nx
   push hl
   ld hl, 2
   push hl
   call sys_div
   call sys_add
   ld hl, c000
   push hl
   call sys_add
   pop hl
   ld (main__inta), hl


   ret


main__inta: defw 0




It is a typical expected RPN output.

Powered by SMFPacks Menu Editor Mod