Author Topic: this in asm : ((ny / 8) * 80) + ((ny % 8) * 2048) + (nx / 2)+ #c000  (Read 3681 times)

0 Members and 1 Guest are viewing this topic.

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.939
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1157
  • Likes Given: 1924
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.


Code: [Select]

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

Offline funkheld

  • 464 Plus
  • *****
  • Posts: 386
  • Liked: 20
  • Likes Given: 0

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

greeting

Offline reidrac

  • Supporter
  • 6128 Plus
  • *
  • Posts: 947
  • Country: gb
  • Trying to gamedev!
    • index.php?action=treasury
    • usebox.net
  • Liked: 1720
  • Likes Given: 953
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 and Brick Rick for the CPC.

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

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.939
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1157
  • Likes Given: 1924
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.



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

Offline reidrac

  • Supporter
  • 6128 Plus
  • *
  • Posts: 947
  • Country: gb
  • Trying to gamedev!
    • index.php?action=treasury
    • usebox.net
  • Liked: 1720
  • Likes Given: 953

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 and Brick Rick for the CPC.

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

Offline ronaldo

  • Dev
  • 6128 Plus
  • *****
  • Posts: 648
  • Country: es
    • Profesor Retroman
  • Liked: 941
  • Likes Given: 827
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.
« Last Edit: 21:18, 20 July 20 by ronaldo »

Offline reidrac

  • Supporter
  • 6128 Plus
  • *
  • Posts: 947
  • Country: gb
  • Trying to gamedev!
    • index.php?action=treasury
    • usebox.net
  • Liked: 1720
  • Likes Given: 953
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 and Brick Rick for the CPC.

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

Offline funkheld

  • 464 Plus
  • *****
  • Posts: 386
  • Liked: 20
  • Likes Given: 0
CPCtelera 2.0. ....... ;) ;) 

1.5  cpctelera is not even out yet.

what's with 2.0?



burns the licenses.
life is easier without licenses ...
« Last Edit: 00:29, 21 July 20 by funkheld »

Offline roudoudou

  • 6128 Plus
  • ******
  • Posts: 947
  • Country: fr
    • urban exploration
  • Liked: 1315
  • Likes Given: 797
Quote

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



Thats the purpose of mit license  ;)
use RASM, the best assembler ever made :p

I will survive

Offline GUNHED

  • 6128 Plus
  • ******
  • Posts: 2.316
  • Country: de
  • Reincarnation of TFM
    • FutureOS - The quickest OS for the CPC and Plus
  • Liked: 1073
  • Likes Given: 2610
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 (Recent update: 2021.01.24)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.02.18)

Offline roudoudou

  • 6128 Plus
  • ******
  • Posts: 947
  • Country: fr
    • urban exploration
  • Liked: 1315
  • Likes Given: 797
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
use RASM, the best assembler ever made :p

I will survive

Offline GUNHED

  • 6128 Plus
  • ******
  • Posts: 2.316
  • Country: de
  • Reincarnation of TFM
    • FutureOS - The quickest OS for the CPC and Plus
  • Liked: 1073
  • Likes Given: 2610
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 (Recent update: 2021.01.24)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.02.18)

Offline roudoudou

  • 6128 Plus
  • ******
  • Posts: 947
  • Country: fr
    • urban exploration
  • Liked: 1315
  • Likes Given: 797
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
use RASM, the best assembler ever made :p

I will survive

Offline roudoudou

  • 6128 Plus
  • ******
  • Posts: 947
  • Country: fr
    • urban exploration
  • Liked: 1315
  • Likes Given: 797
he removed 2 ending brackets because of smileys  ;D
now it's ok for you?
use RASM, the best assembler ever made :p

I will survive

Offline GUNHED

  • 6128 Plus
  • ******
  • Posts: 2.316
  • Country: de
  • Reincarnation of TFM
    • FutureOS - The quickest OS for the CPC and Plus
  • Liked: 1073
  • Likes Given: 2610
Whatever. Back to topic...  ;D ;D ;D
http://futureos.de --> Get the revolutionary FutureOS (Recent update: 2021.01.24)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.02.18)

Offline roudoudou

  • 6128 Plus
  • ******
  • Posts: 947
  • Country: fr
    • urban exploration
  • Liked: 1315
  • Likes Given: 797
Yeah, please Fix the formula in the first post  :P using CODE tag ( # icon )


use RASM, the best assembler ever made :p

I will survive

Offline funkheld

  • 464 Plus
  • *****
  • Posts: 386
  • Liked: 20
  • Likes Given: 0
here in the forum the "(" and the ")" are not output correctly.

Offline zhulien

  • 6128 Plus
  • ******
  • Posts: 588
  • Country: au
    • 8bitology
  • Liked: 240
  • Likes Given: 198
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.